package com.xujl.hsns.codec.impl;

import java.io.ByteArrayOutputStream;
import com.dyuproject.protostuff.JsonIOUtil;
import com.dyuproject.protostuff.XmlIOUtil;
import com.dyuproject.protostuff.runtime.RuntimeSchema;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import com.xujl.hsns.codec.HSNSCodecFactory;
import com.xujl.hsns.test.TEST;
import com.xujl.hsns.test.TI;
import com.xujl.hsns.test.User;

public class JSONCodecFactory implements HSNSCodecFactory {
	
	public JSONCodecFactory(Class decodeClazz){
		decoder= new JSONDecoder(decodeClazz);
		encoder= new JSONEncoder();
	}
	
	 private final JSONEncoder encoder;
	 
	 private final JSONDecoder decoder;



public static void main(String[] args) {
	
	//public abstract java.util.List com.xujl.hsns.test.TEST.add(com.xujl.hsns.test.User)
//	Invoke o=new Invoke(new Object[]{new Integer(0)},"public abstract int com.xujl.hsns.test.TEST.add(int)");
	
	
	
	
	User user = new User(5,"男");
	//sc.invoke(genericString, args);
	try {
		// Greet greet = new Greet();
//		Schema s= new ObjectSchema();
		//MapSchema();
		ByteArrayOutputStream out= new ByteArrayOutputStream();
		XmlIOUtil.writeTo(out, user, RuntimeSchema.createFrom(User.class),javax.xml.stream.XMLOutputFactory.newInstance());
		JsonIOUtil.writeTo(System.out, user,  RuntimeSchema.createFrom(User.class), false);
		System.out.println(new String(out.toByteArray(),"UTF-8"));
	
		//System.out.println(JSONArray.fromObject( sc.invoke(o.getMethod(), o.getArgs())));
	}  catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	
	
}

public ProtocolDecoder getDecoder(IoSession session) throws Exception {
	return decoder;
}

public ProtocolEncoder getEncoder(IoSession session) throws Exception {
	return encoder;
}

}
